home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
Rot13.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-14
|
3KB
|
110 lines
/****************************************************************
* *
* Rot 13 - shift characters 13 positions *
* *
* Copyright © 1990 Karl J. Smith. All Rights Reserved *
* *
* email: ksmith@jarthur.claremont.edu *
* *
* 8/10/90 *
* *
* When debugging, set the project type to application, *
* and add the ANSI project. *
* *
* When all your bugs are out, 'undef' DEBUG, set the project *
* type to Code Resource, with type = ACMD, name = <the name *
* of the function>, file type to 'AEXT', and the purgeable *
* flag set to true. *
* *
* Also, you need to remove the ANSI project from the ACMD *
* project and replace it with the ANSI-A4 project if you use *
* any functions in ANSI, such as strlen. *
* *
* If you are not using THINK C, I'm not quite sure what you *
* should do. :-) *
* *
****************************************************************/
#undef DEBUG
#include <stdio.h>
#include <string.h>
/* Prototypes */
char *
#ifdef DEBUG
dummy(char *inStr);
#else DEBUG
main(char *inStr);
#endif DEBUG
char *
#ifdef DEBUG
dummy(inStr)
#else DEBUG
main(inStr)
#endif DEBUG
char *inStr;
{
char *currentChar;
for (currentChar = inStr; *currentChar != 0; currentChar++)
{
if ((*currentChar >= 'A') && (*currentChar <= 'Z'))
{
*currentChar = ((*currentChar - 'A' + 13) % 26) + 'A';
}
else if ((*currentChar >= 'a') && (*currentChar <= 'z'))
{
*currentChar = ((*currentChar - 'a' + 13) % 26) + 'a';
}
}
return(inStr);
}
#ifdef DEBUG
char * ConvertRtoN(char *theStr);
char * ConvertRtoN(theStr)
char *theStr;
{
char *currentChar;
for (currentChar = theStr;*currentChar != 0; currentChar++)
if (*currentChar == '\r')
*currentChar = '\n';
}
main()
{
char *str = "Nice\rand\reasy\rABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz";
char *ret;
char once[255], twice[255];
strcpy(once, str);
ret = dummy(once);
strcpy(twice, once);
ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
ConvertRtoN(str);
printf("The original is:\n\n%s", str);
printf("\n----\n\nThe result is:\n\n%s", ret);
ret = dummy(twice);
ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
printf("\n----\n\nThe result again is:\n\n%s", ret);
}
#endif DEBUG